package org.wzl.todolisthelper.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wzl.todolisthelper.domain.NormalTask;
import org.wzl.todolisthelper.dto.AddNormalTaskDTO;
import org.wzl.todolisthelper.enumerate.TaskPriorityEnum;
import org.wzl.todolisthelper.service.NormalTaskService;
import org.wzl.todolisthelper.utils.Resp;
import org.wzl.todolisthelper.vo.NormalTaskDetailVO;

@Slf4j
@RestController
@RequestMapping("/normalTask")
public class NormalTaskController {

    @Resource
    private NormalTaskService normalTaskService;

    @PostMapping("/addTask")
    public Resp<?> addTask(@RequestBody AddNormalTaskDTO addNormalTaskDTO) {
        log.info("addTask: {}", addNormalTaskDTO);
        normalTaskService.addTask(addNormalTaskDTO);
        return Resp.ok();
    }

    @GetMapping("/getAllTaskPriority")
    public Resp<?> getAllTaskPriority() {
        return Resp.ok(TaskPriorityEnum.getAll());
    }

    @GetMapping("/getAllCard")
    public Resp<?> getAllCard() {
        return Resp.ok(normalTaskService.getAllCard());
    }

    /**
     *
     * @param id
     * @return
     */
    @GetMapping("/getRawDO")
    public Resp<NormalTask> getRawDO(String id) {
        return Resp.ok(normalTaskService.getById(id));
    }

    @GetMapping("/getDetailById")
    public Resp<NormalTaskDetailVO> getDetailById(String id) {
        return Resp.ok(normalTaskService.getDetailById(id));
    }

    @PostMapping("/uploadTask")
    public Resp<?> uploadTask(@RequestBody NormalTask normalTask) {
        log.info("uploadTask: {}", normalTask);
        normalTaskService.updateById(normalTask);
        return Resp.ok();
    }

    @GetMapping("/completeTask")
    public Resp<?> completeTask(String taskId) {
        log.info("completeTask: {}", taskId);
        normalTaskService.completeTask(taskId);
        return Resp.ok();
    }

    @GetMapping("/deleteTask")
    public Resp<?> deleteTask(String taskId) {
        log.info("deleteTask: {}", taskId);
        normalTaskService.deleteTask(taskId);
        return Resp.ok();
    }

}
